package com.sduept.nwld.dataserver.manager.gismap;

import org.springframework.stereotype.Service;

import java.io.*;
import java.util.Properties;

/**
 * 超级地图引用数据库数据源参数配置
 * @author ldx
 */
@Service

public class SuperMapProperties {
	/**
	 * 单回线路数据集名称
	 */
	private static final String _singlelinetableName="singlelinetableName";
	/**
	 * 双回线路数据集名称
	 */
	private static final String _looplinetableName="looplinetableName";
	/**
	 * 直流线路数据集名称
	 */
	private static final String _dclinetableName="dclinetableName";
	/**
	 * 无杆塔线路数据集名称
	 */
	private static final String _notowerlinetableName="notowerlinetableName";
	/**
	 * 变电站数据集名称
	 */
	private static final String _stationtableName="stationtableName";
	/**
	 * 杆塔数据集名称
	 */
	private static final String _towertableName="towertableName";
	public final static  String SINGLE_LINE_TABLE;
	public final static  String LOOP_LINE_TABLE;
	public final static  String DC_LINE_TABLE;
	public final static  String NOTOWER_LINE_TABLE;
	public final static  String STATION_TABLE;
	public final static  String TOWER_TABLE;
	private  static Properties pro = new Properties();
	static{
		init();
		SINGLE_LINE_TABLE=pro.getProperty(_singlelinetableName);
		LOOP_LINE_TABLE=pro.getProperty(_looplinetableName);
		DC_LINE_TABLE=pro.getProperty(_dclinetableName);
		NOTOWER_LINE_TABLE=pro.getProperty(_notowerlinetableName);
		STATION_TABLE=pro.getProperty(_stationtableName);
		TOWER_TABLE=pro.getProperty(_towertableName);
	}
	public static void init(){
		FileInputStream fis=null;
		try {
			File file= new File("supermap.properties");
			if(!file.exists()){
				file.createNewFile();
				generateProperties(file);
			}
			fis = new FileInputStream(file);
			pro.load(fis);
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(fis!=null){
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	private static void generateProperties(File file){
		BufferedWriter out = null;
		try{
			out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
			out.write("#单回线路数据集");
			out.newLine();
			out.write(_singlelinetableName+"=SMDTV_69");
			out.newLine();
			out.write("#双回线路数据集");
			out.newLine();
			out.write(_looplinetableName+"=SMDTV_7");
			out.newLine();
			out.write("#直流线路数据集");
			out.newLine();
			out.write(_dclinetableName+"=smdtv_9");
			out.newLine();
			out.write("#无杆塔线路数据集");
			out.newLine();
			out.write(_notowerlinetableName+"=SMDTV_5");
			out.newLine();
			out.write("#变电站数据集");
			out.newLine();
			out.write(_stationtableName+"=SMDTV_8");
			out.newLine();
			out.write("#杆塔数据集");
			out.newLine();
			out.write(_towertableName+"=smdtv_4");
			out.newLine();
			out.flush();
		}catch(Exception e){e.printStackTrace();}
		finally{
			if(out!=null)
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
		
	}
	public static void main(String[] args) {
		init();
	}
}
